﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.BUS;
using QuanLyThuVien.VO;

namespace QuanLyThuVien
{


    public partial class frmDangKy : Form
    {

        private busNguoiDung busNguoiDung = new busNguoiDung();

        public frmDangKy()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (String.Compare(txtNguoiDung.Text, "") == 0)
            {
                lblLoi.Text = "Chua Nhap ID";
                lblLoi.Visible = true;
                return;
            }

            if (String.Compare(txtMatKhau.Text, "") == 0)
            {
                lblLoi.Text = "Chua Nhap Password";
                lblLoi.Visible = true;
                return;
            }

            NguoiDung NguoiDung = busNguoiDung.ChonNguoiDung(txtNguoiDung.Text);
            if (NguoiDung != null)
            {
                lblLoi.Text = "Nguoi Dung da Ton tai";
                lblLoi.Visible = true;
                return;
            }

            lblLoi.Visible = false;
            
            busNguoiDung.DangKy(txtNguoiDung.Text, txtMatKhau.Text);

            this.Close();
        }

        private void txtNguoiDung_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && 
                !Char.IsLetter(e.KeyChar) && 
                !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void txtMatKhau_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) &&
                !Char.IsLetter(e.KeyChar) &&
                !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
